import util.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Jason
 * @PACKAGE_NAME PACKAGE_NAME
 * @Description 查询数据
 * @date 2023-12-06 14:57
 */
public class Query {
    public static void query() throws SQLException, ClassNotFoundException {
        String sql = "select * from sys";
        DbUtil dbUtil = new DbUtil();
        Connection conn = dbUtil.getConnection();
        PreparedStatement pst = conn.prepareStatement(sql);
        ResultSet resultSet = pst.executeQuery();
        /*executeQuery.next()判断是否还有下一条数据*/
        while (resultSet.next()){
            int id = resultSet.getInt("id");
            String username = resultSet.getString("username");
            String password = resultSet.getString("password");
            System.out.println("id:" + id + " " + "username:" + username + " " + "password:" + password);
            System.out.println("-------------------------");
        }
        dbUtil.closeStatement(pst);
        dbUtil.closeConnection(conn);
        dbUtil.closeResultSet(resultSet);
    }

    public static void main(String[] args) {
        try {
            Query.query();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
